package com.jyy.prefabricated.controller;


import com.jyy.prefabricated.common.AjaxResult;
import com.jyy.prefabricated.entity.ResumeInfoWorkHis;
import com.jyy.prefabricated.service.ResumeInfoWorkHisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 简历工作经历
 * @version 1.0.0
 * @author: zjj
 */
@Slf4j
@RequestMapping("/api")
@RestController
public class ResumeInfoWorkHisController {

    @Autowired
    private ResumeInfoWorkHisService workHisService;

    /**
     * 新增工作经历
     * @param workHis
     * @return
     */
    @PostMapping("/resumes-work-his")
    public AjaxResult insert(@Valid @RequestBody ResumeInfoWorkHis workHis){
        log.info("Rest request to insert workHis:{}",workHis);
        Integer id = workHisService.insert(workHis);
        ResumeInfoWorkHis result = workHisService.selectById(id);
        return AjaxResult.success(result);
    }

    /**
     * 修改工作经历
     * @param workHis
     * @return
     */
    @PutMapping("/resumes-work-his")
    public AjaxResult update(@Valid @RequestBody ResumeInfoWorkHis workHis){
        log.info("Rest request to update workHis:{}",workHis);
        workHisService.update(workHis);
        ResumeInfoWorkHis result = workHisService.selectById(workHis.getId());
        return AjaxResult.success(result);
    }

    /**
     * 查询工作经历详情
     * @param id
     * @return
     */
    @GetMapping("/resumes-work-his/{id}")
    public AjaxResult selectById(@PathVariable Integer id){
        log.info("Rest request to find workHis by id:{}",id);
        ResumeInfoWorkHis result = workHisService.selectById(id);
        return AjaxResult.success(result);
    }

    /**
     * 删除工作经历
     * @param id
     * @return
     */
    @DeleteMapping("/resumes-work-his/{id}")
    public AjaxResult deleteById(@PathVariable Integer id){
        log.info("Rest request to delete workHis by id:{}",id);
        int row = workHisService.delete(id);
        if(row > 0){
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }


}
